package com.krui.iweibo.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.krui.iweibo.R;
import com.krui.iweibo.dao.DataBaseAccess;
import com.krui.iweibo.model.UserInfo;


public class BaseActivity extends Activity {
	
	protected DataBaseAccess dbAccess;
	
	/** 当前登录用户*/
	protected UserInfo currentUser;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/** 初始化数据库*/
		DataBaseAccess.initDataBaseAccess(this);
		/** 得到数据库操作实例*/
		dbAccess = DataBaseAccess.getInstance();
	}
	
	/**
	 * 显示提示信息
	 * @param message: 提示内容
	 */
	protected final void showHintDialog(String message){
		new Builder(this).setTitle(R.string.lable_hint_title).setMessage(message).setPositiveButton(R.string.btn_lable_yes,null).create().show();
	}
	
	/**
	 * 跳转到目的activity
	 * @param context 上下文对象
	 * @param obj 目的界面
	 * @param autofinish 是否finish当前activity
	 */
	protected void intent2Where(Context context,Class<?> obj,boolean autofinish){
		Intent intent = new Intent(context,obj);
		startActivity(intent);
		overridePendingTransition(R.anim.anim_enter, R.anim.anim_exit);
		if (autofinish) {
			((Activity) context).finish();
		}
	}
	
	/**
	 * 退出应用程序
	 */
	protected final void exitApplication(){
		new AlertDialog.Builder(this)
		.setMessage(R.string.warring_exit)
		.setPositiveButton(R.string.btn_lable_yes, new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				if(which == DialogInterface.BUTTON_POSITIVE){
					finish();
					System.exit(0);
				}
			}})
		.setNegativeButton(R.string.btn_lable_no, null)
		.create()
		.show();
	}

}